package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyLifeCircleLike;
import com.laowang.project.system.service.MyLifeCircleLikeService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 车友圈点赞Controller
 *
 * @author laowang
 * @date 2023-04-25
 */
@Api(tags = "车友圈点赞接口")
@RestController
@RequestMapping("/circleLifeLike")
public class MyLifeCircleLikeController extends BaseController {
    @Autowired
    private MyLifeCircleLikeService myLifeCircleLikeService;

    @ApiOperation(value = "小程序端 车友圈点赞",notes = "")
    @GetMapping(value = "/web/like/{id}")
    public AjaxResult like(@PathVariable("id") Integer id) {
        Integer mid = SecurityUtils.getLoginUser().getWxUser().getMid();
        MyLifeCircleLike myLifeCircleLike =new MyLifeCircleLike();
        myLifeCircleLike.setUserId(mid);
        myLifeCircleLike.setLifeCircleId(id);
        List<MyLifeCircleLike> myLifeCircleLikes = myLifeCircleLikeService.selectMyLifeCircleLikeList(myLifeCircleLike);
        if (myLifeCircleLikes.size()>0){
            return AjaxResult.success("已经点赞啦!");
        }
        myLifeCircleLike.setIsEnable("1");
        Integer i = myLifeCircleLikeService.addLike(myLifeCircleLike);

        return AjaxResult.success("操作成功",i);
    }


    /**
     * 查询车友圈点赞列表
     */
    @ApiOperation(value = "查询车友圈点赞列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:circleLifeLike:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyLifeCircleLike myLifeCircleLike) {
        startPage();
        List<MyLifeCircleLike> list = myLifeCircleLikeService.selectMyLifeCircleLikeList(myLifeCircleLike);
        return getDataTable(list);
    }

    /**
     * 导出车友圈点赞列表
     */
    @ApiOperation(value = "导出车友圈点赞列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:circleLifeLike:export')")
    @Log(title = "车友圈点赞", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyLifeCircleLike myLifeCircleLike) {
        List<MyLifeCircleLike> list = myLifeCircleLikeService.selectMyLifeCircleLikeList(myLifeCircleLike);
        ExcelUtil<MyLifeCircleLike> util = new ExcelUtil<MyLifeCircleLike>(MyLifeCircleLike.class);
        return util.exportExcel(list, "circleLifeLike");
    }

    /**
     * 获取车友圈点赞详细信息
     */
    @ApiOperation(value = "获取车友圈点赞详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('system:circleLifeLike:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myLifeCircleLikeService.selectMyLifeCircleLikeById(id));
    }

    /**
     * 新增车友圈点赞
     */
    @ApiOperation(value = "新增车友圈点赞",notes = "")
    @PreAuthorize("@ss.hasPermi('system:circleLifeLike:add')")
    @Log(title = "车友圈点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyLifeCircleLike myLifeCircleLike) {
        return toAjax(myLifeCircleLikeService.insertMyLifeCircleLike(myLifeCircleLike));
    }

    /**
     * 修改车友圈点赞
     */
    @ApiOperation(value = "修改车友圈点赞",notes = "")
    @PreAuthorize("@ss.hasPermi('system:circleLifeLike:edit')")
    @Log(title = "车友圈点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyLifeCircleLike myLifeCircleLike) {
        return toAjax(myLifeCircleLikeService.updateMyLifeCircleLike(myLifeCircleLike));
    }

    /**
     * 删除车友圈点赞
     */
    @ApiOperation(value = "删除车友圈点赞",notes = "")
    @PreAuthorize("@ss.hasPermi('system:circleLifeLike:remove')")
    @Log(title = "车友圈点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myLifeCircleLikeService.deleteMyLifeCircleLikeByIds(ids));
    }
}
